﻿using System;
using System.Collections.Generic;

namespace MSDNWebcast.Models
{
    /// <summary>
    /// Webcast 课程
    /// </summary>
    public class Course
    {
        /// <summary>
        /// 课程ID
        /// </summary>
        public string EventID { get; set; }

        /// <summary>
        /// 讲师
        /// </summary>
        public string Speaker { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Headline { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 课程级别
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// 课程系列
        /// </summary>
        public string Series { get; set; }

        /// <summary>
        /// 课程日期
        /// </summary>
        public DateTime Date { get; set; }

        /// <summary>
        /// 相关产品
        /// </summary>
        public string Products { get; set; }

        /// <summary>
        /// 技术
        /// </summary>
        public string Technology { get; set; }

        /// <summary>
        /// MSDN Webcast 网站链接
        /// </summary>
        public string Url { get; set; }

        /// <summary>
        /// 可下载的文件类型
        /// </summary>
        public List<FileType> Files { get; set; }

        /// <summary>
        /// 课程序列
        /// </summary>
        public int CourseIndex { get; set; }

        /// <summary>
        /// 广播是否已下载
        /// </summary>
        /// <returns></returns>
        public bool HaveDownload()
        {
            foreach (var fileType in Files)
            {
                var file = new CourseFile(this, fileType);
                if (file.CanOpen) return true;
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj != null && obj is Course && !ReferenceEquals(obj, this))
                return ((Course)obj).EventID == this.EventID;
            return base.Equals(obj);
        }
    }
}
